package org.geektimes.projects.microprofile.config.source;

import org.eclipse.microprofile.config.spi.ConfigSource;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Java Default ConfigSource, As a bottom-up solution
 *
 * @author biwin
 */
public class DefaultResourceConfigSource extends MapBasedConfigSource {

    public DefaultResourceConfigSource() {
        super(0, "DefaultConfigSource");
    }

    @Override
    protected void prepareConfigData(Map configData) throws Throwable {
        Properties properties = new Properties();
        InputStream in = DefaultResourceConfigSource.class.getResourceAsStream("/META-INF/configSource.properties");
        try {
            properties.load(in);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        configData.putAll(properties);
    }

}
